package com.itheima;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtParser;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.junit.jupiter.api.Test;

import java.util.Date;
import java.util.HashMap;

public class JwTtest {
    @Test
    public void testGenJwt(){
        HashMap<String, Object> claims = new HashMap<>();
        String jwt = Jwts.builder().signWith(SignatureAlgorithm.HS256, "pengpam")
                .addClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis() + 12 * 3600 * 1000))
                .compact();

        System.out.println(jwt);
    }
    @Test
    public void testParseJwt(){
        Claims claims = Jwts.parser().setSigningKey("pengpam")
                .parseClaimsJws("eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NTM5NzcwMzJ9.uDFx3vQgO356vZX7rU8fmEZ_rTL3aiI6lpxMRo0i3Ic")
                .getBody();
        System.out.println(claims);

    }
}
